package com.bing.document;

import java.util.HashMap;
import java.util.Map;

import net.semanticmetadata.lire.builders.DocumentBuilder;
import net.semanticmetadata.lire.builders.GlobalDocumentBuilder;

public class GlobalDocumentBuilderFactory implements DocumentBuilderFactory {
	
	private static DocumentBuilderFactory INSTANCE = new GlobalDocumentBuilderFactory();
	
	private GlobalDocumentBuilderFactory() {
	}

	private static final Map<GlobalFeature, GlobalDocumentBuilder> HOLDER = new HashMap<>(32);

	private static final boolean HASHING = false;

	private static final boolean USE_DOC_VALUES = true;
	
	static {

		for (GlobalFeature globalFeature : GlobalFeature.GLOBAL_FEATURES) {
			GlobalDocumentBuilder globalDocumentBuilder = new GlobalDocumentBuilder(HASHING, USE_DOC_VALUES);
			globalDocumentBuilder.addExtractor(globalFeature.getGlobalFeatureClazz());
			HOLDER.put(globalFeature, globalDocumentBuilder);
		}
	}

	@Override
	public DocumentBuilder getGlobalDocumentBuilder() {
		return HOLDER.get(DEFAULT_FEATURE);
	}
	
	@Override
	public DocumentBuilder getGlobalDocumentBuilder(
			Class<? extends net.semanticmetadata.lire.imageanalysis.features.GlobalFeature> globalFeatureClass) {
		return this.getGlobalDocumentBuilder(GlobalFeature.getGlobalFeature(globalFeatureClass));
	}

	@Override
	public DocumentBuilder getGlobalDocumentBuilder(GlobalFeature globalFeature) {
		return HOLDER.get(globalFeature);
	}
	
	public static DocumentBuilderFactory instance() {
		return INSTANCE;
	}

}
